import React, { PureComponent } from 'react';
import { connect } from 'dva';
import PropTypes from 'prop-types';
import { Form } from '@ant-design/compatible';
import '@ant-design/compatible/assets/index.css';
import { Menu, Dropdown } from 'antd';
import { PrimaryC, PrimaryGhostC } from '../../../../comps';
import style from './index.less';
import FormDataC from '../../../Product/moneyInformation/formDataC.js';
import ZcBaseInfo from '../../../Product/nonstandarmaintenanceNew/FormContent/BaseInfo/zcBaseInfo.js';
const { SubMenu } = Menu;
@Form.create()
@connect(({ loading, globalM, informationM, nonstandarmaintenanceNewM }) => ({
  loading,
  globalM,
  informationM,
  nonstandarmaintenanceNewM,
}))
export default class BaseInfo extends PureComponent {
  state = {};
  componentDidMount() {
    const {
      globalM: { dataDictionary },
      securityType,
    } = this.props;
    // 非理财直融字典
    let dictMapSelect = {};
    let keyArr = [
      'INVEST_ASSET_TYPE',
      'INVEST_CURRENCY',
      'INVEST_JYLTCS',
      'INVEST_TYPE',
      'ASSETS_ASSET_TYPE',
      'ASSETS_RATE_TYPE',
      'ASSETS_INTEREST_BASIS',
      'ASSETS_MAIN_RATING_START',
      'ASSETS_REPAY_WAY',
      'ASSETS_GUARANTEE_WAY',
      'ASSETS_SSYQLX1',
      'NONSTANDAR_JGBB_SSYQLX1',
      'ASSETS_JXLX',
      'ASSETS_LXFBFS',
      'ASSETS_JZLLZL',
      'ASSETS_JGDC',
      'ASSETS_HBFS1',
      'ASSETS_RZRLXGM',
      'ASSETS_RZRLXJS',
      'ASSETS_RZRLXJJ',
      'ASSETS_ZDJKHYHLYLB',
      'ASSETS_DZYWLX',
      'ASSETS_DBXZ1',
      'ASSETS_DBRYRZRGX',
      'ASSETS_HQLX1',
      'ASSETS_XQFS1',
      'ASSETS_YXTKLX',
      'ASSETS_LXDYTKLX',
      'ASSETS_TXBFFL', //投向部分分类
    ];
    Object.getOwnPropertyNames(dataDictionary).forEach(function (key) {
      keyArr.map((item) => {
        if (key == item) {
          dictMapSelect[key] = dataDictionary[key].map((ele) => {
            return { value: ele.code, title: ele.value };
          });
        }
      });
    });
    this.props.dispatch({
      type: 'nonstandarmaintenanceNewM/save',
      payload: {
        dictMapSelect,
      },
    });
  }
  UNSAFE_componentWillReceiveProps(nextProps) {}

  // 新增操作下拉
  menu = () => {
    return (
      <Menu onClick={this.handleMenuClick}>
        <Menu.Item key='1'>理财直融</Menu.Item>
        <Menu.Item key='2'>非理财直融</Menu.Item>
      </Menu>
    );
  };

  handleMenuClick = (e) => {
    if (e.key == '1') {
      this.props.changePage(4);
      this.props.securityTypeChange('7');
    } else {
      this.props.changePage(4);
      this.props.securityTypeChange('12');
    }
  };

  render() {
    const {
      form,
      securityType,
      informationM: { basicInfo, formDatas },
    } = this.props;
    return (
      <div>
        <div style={{ display: 'flex', justifyContent: ' flex-end', marginBottom: '16px' }}>
          <Dropdown overlay={this.menu} trigger={['click']}>
            <PrimaryC title='新增' style={{ marginRight: '10px' }} />
          </Dropdown>
          <PrimaryGhostC
            title='编辑'
            onClick={() => {
              this.props.changePage(5);
              this.props.securityTypeChange(securityType);
            }}
          />
        </div>
        {securityType == '7' ? (
          <FormDataC type={5} init={basicInfo} onRef={(ref) => (this.formData = ref)} form={form} />
        ) : (
          <ZcBaseInfo disableStatus={true} baseInfo={formDatas.baseInfo} onRef={(ref) => (this.zc = ref)} />
        )}
      </div>
    );
  }
}

// props默认值
BaseInfo.propsTypes = {
  securityType: PropTypes.string, // 标的类型：7-非标(理财直融) 12- 非标(非理财直融)
  securityTypeChange: PropTypes.func, // 改变标的类型
  changePage: PropTypes.func, // 改变是否显示主页面
};
